<template>
	<view class="enterprise-change-record">
		<titleName :name="name"></titleName>
		<view class="title-bgc"></view>
		<view class="content-wrap">
			<view style="background-color: #fff;padding-bottom: 2rpx;margin-bottom: 24rpx;">
				<view class="search-wrap">
					<view style="display: flex;justify-content: space-between;">
						<view class="ipt-wrap">
							<view style="margin-left: 10rpx;display: flex;align-items: center;">
								<uni-data-select placeholder="涉废类型" v-model="queryParams.wastetype"
									:localdata="adviceTypeList" :clear="true">
								</uni-data-select>
								<view class="line"></view>

								<uni-datetime-picker start-placeholder="日" rangeSeparator="—" end-placeholder="期"
									type="daterange" @change="dateChange" />
								<!-- <uni-icons type="down" v-if="!queryParams.startdate" size="15"
									style="margin-left: 8rpx;position: absolute;top: 50%;transform: translateY(-50%);left: 74rpx;" /> -->
							</view>
							<!-- <view class="line"></view> -->
							<!-- 	<input type="text" placeholder-class="ipt-class" v-model='queryParams.devicename'
								placeholder="请输入设施名称" /> -->
						</view>
						<button @click="getList">查询</button>
					</view>

				</view>
				<!-- <view class="date-wrap">
					<view class="date-ipt" style="width:574rpx;position: relative;overflow: hidden;">

					</view>
				</view> -->
			</view>

			<!-- <view style="padding-left: 30rpx;">
				<uni-datetime-picker type="daterange" rangeSeparator="—" @change="dateChange" start-placeholder="日"
					end-placeholder="期" />
			</view> -->
			<view class="unit-num">
				共<text>{{total}}</text>条记录
			</view>
			<view class="list">
				<noData v-if="dataList.length==0" />
				<view class="item" @click="jumpChangeRecordDetail(item.id)" v-for="item in dataList" :key="item.id">
					<view class="title">
						<view class="name">企业名称：{{enterpriseList?.find((i)=>i.id==item.enterpriseid)?.customername }}
						</view>
						<image
							src="https://splendid.oss-cn-beijing.aliyuncs.com/static/imghazardouswaste/right-arrow.png"
							mode=""></image>
					</view>
					<view class="device">
						设施名称：{{item.devicename}}
					</view>
					<view class="type">
						涉废类型：{{adviceTypeList?.find(i=>i.value==item.wastetype)?.text }}
					</view>
					<view class="time">
						本次更换时间：{{item.committime || '无'}}
					</view>
				</view>








			</view>



		</view>

	</view>
</template>

<script setup>
	//红色字体颜色 #FA0808  backgound:#FFC9C9
	//橙色字体颜色 #FA7408  backgound:#FFEAC9
	//产废字体颜色 #FF0000
	//正常字体颜色 #0874FA
	//关闭字体颜色 #FA0808
	//停产字体颜色 #FA0808
	import titleName from '../../components/titleName.vue'
	import noData from '../../components/noDataShow.vue'
	import http from '../../request/index'
	import uploadFile from '../../request/uploadFile.js'
	import {
		onShow,
		onLoad
	} from '@dcloudio/uni-app'
	import {
		reactive,
		ref
	} from 'vue'
	let adviceTypeList = ref([])
	let name = ref("更换记录")
	let recordType = ref(1)
	let showLine = ref('none')
	let dataTree = ref()
	let dataList = ref([])
	let enterpriseList = ref([])
	let total = ref('0')
	let enterpriseid = ref('')
	let deviceid = ref('')
	let queryParams = reactive({

	})
	let jumpChangeRecordDetail = (id) => {
		uni.navigateTo({
			url: `/contorllerPageOther/adminchangerecorddetail/adminchangerecorddetail?id=${id}`
		})
	}
	onLoad((e) => {
		enterpriseid.value = e.enterpriseid
		deviceid.value = e.deviceid
		getList()
	})
	let dateChange = (e) => {
		console.log(e, 'e');
		if (e.length == 0) {
			queryParams.startdate = ''
			queryParams.enddate = ''
			showLine.value = 'none'
			return
		}
		queryParams.startdate = e[0]
		queryParams.enddate = e[1]
		showLine.value = 'block'
	}
	let getList = () => {
		http({
			url: '/stock/datalist',
			data: {
				enterpriseid: enterpriseid.value,
				devicecode: deviceid.value,
				...queryParams
			}
		}).then((res) => {
			if (res.code == 0) {
				dataList.value = res.data.list
				console.log(dataList, 'flist');
				total.value = res.data.total
			}

		})
	}

	function mapTree(data) {
		console.log(data, 'data');
		if (data.length <= 0) return

		return data.map((item) => {
			item.text = item.regionname
			item.value = item.id
			if (item.lstSubNodes && item.lstSubNodes.length > 0) {
				item.children = item.lstSubNodes
				for (var i = 0; i < item.lstSubNodes.length; i++) {

					item.children[i].text = item.lstSubNodes[i].regionname
					item.children[i].value = item.lstSubNodes[i].id
					if (item.lstSubNodes[i].lstSubNodes && item.lstSubNodes[i].lstSubNodes.length > 0) {
						mapTree(item.lstSubNodes[i].lstSubNodes)
					}


				}
			}
			return item

		})

	}

	http({
		url: '/listitem/getmodule',
		data: {
			module: 'B03'
		}
	}).then((res) => {
		if (res.code == 0) {
			let data = res.data
			adviceTypeList.value = data.map((item) => {
				return {
					text: item.name,
					value: item.id
				}
			})

		}

	})
	http({
		url: '/enterprise/datalist'
	}).then((res) => {
		if (res.code == 0) {
			enterpriseList.value = res.data.list
		}
	})
	http({
		url: '/region/datalisttree'
	}).then((res) => {
		if (res.code == 0) {
			let data = res.data
			let cc = mapTree(data)
			dataTree.value = data



		}

	})
	onShow(() => {

	})

	let jumpDetail = () => {
		uni.navigateTo({
			url: "/contorllerPageOther/wasteenterprisefiltrate/wasteenterprisefiltrate"
		})
	}
</script>

<style lang="scss" scoped>
	:deep(.ipt-class) {

		font-weight: 400;
		font-size: 24rpx;
		color: #999999;


	}

	:deep(.uni-date-x) {
		flex: none;
		background-color: none;
		height: 63rpx;
		line-height: 63rpx;
	}

	:deep(.uniui-down) {
		color: #999 !important;
	}

	:deep(.uniui-clear) {
		font-size: 48rpx !important;
	}

	:deep(.range-separator) {
		background-color: #fff;
		display: v-bind('showLine');
		height: 65rpx !important;
		line-height: 63rpx !important;
	}

	:deep(.uni-select) {
		border: none !important;


		font-weight: 400;
		font-size: 25rpx;
		color: #333333;

	}

	:deep(.placeholder) {

		font-weight: 400;
		font-size: 25rpx;
		color: #333333;

	}

	:deep(.icon-calendar) {
		display: none;
	}

	:deep(.uni-date) {
		background-color: #fff;
		// width: auto !important;
		// flex: none !important;
		overflow: hidden;
	}

	:deep(.uni-date__x-input) {
		font-weight: 400;
		font-size: 25rpx;
		color: #333333;
		text-align: center;
		background-color: #F3F5F7;
		flex: none;
		background-color: #fff;
	}

	:deep(.input-value-border) {
		border: none !important;
	}

	:deep(.uni-date-editor--x) {
		border: none;
	}

	.enterprise-change-record {
		width: 100vw;
		height: 100vh;

		.title-bgc {
			width: 750rpx;
			height: 160rpx;
			background: #0874FA;
		}

		.content-wrap {
			width: 100vw;
			height: calc(100vh - 160rpx);
			background-color: #F3F5F7;
			display: flow-root;


			.list {
				height: calc(100vh - 80rpx - 300rpx);
				display: flex;
				flex-direction: column;
				align-items: center;
				overflow: auto;

				margin-top: 20rpx;

				.item:first-child {
					margin-top: 0 !important;
				}

				.item {
					width: 707rpx;
					height: 270rpx;
					background: #FFFFFF;
					border-radius: 14rpx;
					padding: 30rpx 30rpx 30rpx 40rpx;
					margin-top: 25rpx;
					display: flex;
					flex-direction: column;


					.title {

						display: flex;
						align-items: center;
						justify-content: space-between;

						.name {

							font-weight: 500;
							font-size: 31rpx;
							color: #222222;

						}

						image {
							width: 15rpx;
							height: 25rpx;
						}
					}

					.device,
					.type,
					.time {
						margin-top: 18rpx;
						font-weight: 400;
						font-size: 28rpx;
						color: #666666;


					}


				}
			}

			.unit-num {
				margin-top: 3rpx;
				font-weight: 400;
				font-size: 23rpx;
				color: #333333;
				margin-bottom: 22rpx;
				padding-left: 30rpx;

				text {
					color: #0874FA;
				}
			}

			.date-wrap {
				padding-left: 22rpx;
				margin-bottom: 16rpx;
				margin-top: 6rpx;

				.date-ipt {
					display: flex;
					max-width: 574rpx;
					align-items: center;
					border: 1px solid #ccc;
					border-radius: 34rpx;
					padding-left: 30rpx !important;

					.date {
						color: #333;
						font-size: 24rpx;
					}

					.line {
						width: 1rpx;
						height: 30rpx;
						background-color: #9eaaba;
						margin-left: 15rpx;
						margin-right: 15rpx;
					}
				}
			}

			.search-wrap {
				display: flex;
				flex-direction: column;
				padding: 26rpx 22rpx 0 22rpx;
				justify-content: space-between;
				width: 750rpx;
				height: 112rpx;
				background: #fff;


				.ipt-wrap {
					width: 574rpx;
					height: 67rpx;
					background: #FFFFFF;
					border-radius: 34rpx;
					display: flex;
					align-items: center;
					border: 1px solid #ccc;

					input {
						flex: 1;
						flex-shrink: 1;
						font-weight: 400;
						font-size: 24rpx;
						color: #999999;
						padding-left: 10rpx;
						padding-right: 20rpx;
					}

					.line {
						width: 1rpx;
						height: 35rpx;
						background: #E8E8E8;
						margin-left: 15rpx;
						margin-right: 20rpx;
					}
				}

				button {
					width: 118rpx;
					height: 67rpx;
					background: #0874FA;
					border-radius: 34rpx;
					font-weight: 400;
					font-size: 25rpx;
					color: #FFFFFF;
					line-height: 67rpx;

				}
			}



		}
	}
</style>